import {logUtil} from "../util/logUtil";
import {Util} from "../util/Util";

/**
 * 对象
 */
export interface BattleAgent {
    //标识
    id: number;
    //标识
    hp: number;

    mp?: number;

    energy?: number;

    atk?: number;
    // 可以添加BattleAgent的相关属性和方法

}

//region 效果
export interface IEffect {
    // 应用效果到目标
    apply(target: any): void;

    // 移除效果
    remove(target: any): void;

}

export class Effect implements IEffect {
    level: number = 1;//运行数据,当前等级
    //id
    id: number;
    name: string;
    iconIndex: number;
    iconPath: string;
    description: string;
    lastUsedTime: number;
    version: number;

    num?: number[];
    //增益与否
    isBuff: boolean;
    class: string;
    //持续时长
    duration?: number[];
    damPerS?: number[];

    levelMax: number;
    //触发方式
    triggerWay: number;
    //----------非数据库字段----------
    attackUp?: number[];
    //定时器id
    timerId?: number | null;

    //日志控制器
    log = logUtil.instance
    logLevel = "Effect"

    constructor(data: {
        //通用
        id: number,
        name: string,
        iconIndex: number,
        iconPath: string,
        description: string,
        lastUsedTime: number,
        version: number,
        isBuff: string,
        class: string,
        //通用数据
        num?: string,
        levelMax: number,
        triggerWay: number,
        //灼烧
        duration?: string,
        damPerS?: string,
        //增伤
        attackUp?: string,
    }) {
        this.id = data.id;
        this.name = data.name;
        this.iconIndex = data.iconIndex;
        this.iconPath = data.iconPath;
        this.description = data.description;
        this.lastUsedTime = data.lastUsedTime;
        this.version = data.version;
        this.duration = Util._stringToArrayByComma(data.duration,1000);
        this.damPerS = Util._stringToArrayByComma(data.damPerS);
        this.isBuff = data.isBuff == "0" ? false : true;
        this.class = data.class;
        this.attackUp = Util._stringToArrayByComma(data.attackUp);
        this.num = Util._stringToArrayByComma(data.num);
        this.levelMax = data.levelMax;
        this.triggerWay = data.triggerWay;
    }

    apply(target: any): any {
        this.log.log('Effect', `使用了${this.logLevel}的${this.level}等级的技能`);
    }

    remove(target: any): void {
    }

}

//endregion

//region 触发器
export interface ITrigger {
    // 检查效果是否应该触发
    shouldTrigger(condition: any): boolean;
}

export class Trigger implements ITrigger {
    shouldTrigger(condition: any): boolean {
        return false;
    }
}

//endregion
